package seGobangClient;

import java.awt.Font;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author plus
 */
public class GlobalController
{

    private static Options currentOptions;
    private static Rule currentRule;
    private static ISceneController currentSceneController;
    private static IUISystem currentUISystem;

    public GlobalController(javax.swing.JFrame UIContainer)
    {
        currentRule = new Rule();
        currentOptions = new Options();
        currentOptions.LoadFromXML();
        currentRule.LoadFromXML();
        if (currentOptions.GraphicMode == -1)
        {
            Font font = new Font("宋体", Font.PLAIN, 13);
            UIManager.put("OptionPane.messageFont", font);
            UIManager.put("OptionPane.buttonFont", font);
            Object[] options = {"2D", "3D"};
            int response = JOptionPane.showOptionDialog(null, "<html>第一次运行本游戏<br>请选择模式", "模式选择", JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE,
                    null, options, options[1]);
            if (response == 0)
            {
                currentOptions.GraphicMode = currentOptions.SysConfig_2DGraphic;
                currentOptions.SaveToXML();
            } else if (response == 1)
            {
                currentOptions.GraphicMode = currentOptions.SysConfig_3DGraphic;
                currentOptions.SaveToXML();
            }
            else System.exit(0);
        }
        if (currentOptions.GraphicMode == currentOptions.SysConfig_3DGraphic)
        {
            UIContainer.setSize(800, 600);
            currentUISystem =
                    new seGobangClient.uiSystem3D.SceneManager(UIContainer);
        } else if (currentOptions.GraphicMode == currentOptions.SysConfig_2DGraphic)
        {
            currentUISystem =
                    new seGobangClient.uiSystem2D.SceneManager(UIContainer);
        }

        currentSceneController =
                new seGobangClient.mainMenu.MainMenuController(currentUISystem);
    }

    public static Options getCurrentOptions()
    {
        return currentOptions;
    }

    public static void setCurrentOptions(Options currentOptions)
    {
        GlobalController.currentOptions = currentOptions;
    }

    public static Rule getCurrentRule()
    {
        return currentRule;
    }

    public static void setCurrentRule(Rule currentRule)
    {
        GlobalController.currentRule = currentRule;
    }

    public static void setCurrentSceneController(ISceneController currentSceneController)
    {
        GlobalController.currentSceneController = currentSceneController;
    }

    public static IUISystem getCurrentUISystem()
    {
        return currentUISystem;
    }
}
